<?

$thisMdl        = "CASH-BANK";
$mdlNumber      = "31";

$entryBoxStyle  = " style='width:110;height:40;
                           font-size:100%;
                           font-weight:bold;' ";

$GHtml       = new CGHtml;
$GJs         = new CGJavascript;
$Misc        = new Misc;
$CLFetchers  = new CLFetchers;
$CFetchers   = new GlobalFetchers;
$SourceDb    = new Composer;
$SourceDb    = $SourceDb->init("db");

$SourceDb->add("srcDbHdr",             "C_B_HDR");
$SourceDb->add("srcDbDtl",             "C_B_DTL");
$SourceDb->add("srcDbSubDtl",          "C_B_SUB_DTL");
$SourceDb->add("srcDbCbTx",            "MST_CASH_BANK_TX");
$SourceDb->add("srcDbMstCurrency",     "MST_CURRENCY");
$SourceDb->add("srcDbTxType",          "MST_CASH_BANK_TX");
$SourceDb->add("srcDbMstCb",           "MST_CASH_BANK");
$SourceDb->add("srcDbCustomer",        "CUSTOMER");
$SourceDb->add("srcDbSupplier",        "SUPPLIER");

//check if the user has the entry priv
if($UID->getPrivsByNumber( $mdlNumber, _ENTRY_RIGHTS) > 0){

	//check entry
	$bodyPart	=	"<tr>\n".
							"  <td> ".$GHtml->formInputButton("<font size='5'>Entry</font>", // The label
        							                           "entry",                       // var Name
        							                           "entry",                       // var value
        							                           $entryBoxStyle)." </td>\n";    // var properties
}else{

	$bodyPart	=	"<tr>\n";
}

$optPrivs = "";
if($UID->getPrivsByNumber( $mdlNumber, _VIEW_RIGHTS) > 0){

	$optPrivs .=	"  <td> ".$GHtml->formInputButton("<font size='5'>View</font>", // The label
          							                           "view",                       // var Name
          							                           "View",                       // var value
          							                           $entryBoxStyle)." </td>\n";   // var properties
}
if($UID->getPrivsByNumber( $mdlNumber, _MODIFY_RIGHTS) > 0){

	$optPrivs .=	"  <td> ".$GHtml->formInputButton( "<font size='5'>Modify</font>", // The label
            							                          "modify",                       // var Name
            							                          "Modify",                       // var value
            							                          $entryBoxStyle)." </td>\n";     // var properties
}
if($UID->getPrivsByNumber( $mdlNumber, _APPROVED_RIGHTS) > 0){

	$optPrivs	.=	"  <td> ".$GHtml->formInputButton( "<font size='5'>Approve</font>", // The label
            							                          "approve",                       // var Name
            							                          "Approve",                       // var value
            							                          $entryBoxStyle)." </td>\n";      // var properties
}
if($UID->getPrivsByNumber( $mdlNumber, _DELETE_RIGHTS) > 0){

	$optPrivs	.=	"  <td> ".$GHtml->formInputButton( "<font size='5'>Cancel</font>", // The label
            							                          "cancel",                       // var Name
            							                          "Cancel",                       // var value
            							                          $entryBoxStyle)." </td>\n";     // var properties
}
if($UID->getPrivsByNumber( $mdlNumber, _EDIT_RIGHTS) > 0){

	$optPrivs	.=	"  <td> ".$GHtml->formInputButton( "<font size='5'>Delete</font>", // The label
            							                          "delete",                       // var Name
            							                          "Delete",                       // var value
            							                          $entryBoxStyle)." </td>\n";     // var properties
}


if($_POST["range_period1"]){

  $condt  = " AND H.TR_DATE >= TO_DATE('" .$_POST["range_period1"]. " ','dd-mm-yyyy')
 	            AND H.TR_DATE <= to_date('" .$_POST["range_period2"]. "','dd-mm-yyyy')";
}else{

  $condt  = " AND H.TR_DATE<ADD_MONTHS(TO_DATE('".$_SESSION["sysPeriode"]. "','MM-YYYY'),1)
 	            AND H.TR_DATE>=TO_DATE('".$_SESSION["sysPeriode"]."','MM-YYYY') ";
}


//check if criteria is null then default is by entried
//process criteria
switch($_POST["criterialist"]){

	case "pending":
		$partCriteria = "WHERE  H.STATUS='"._NOT_ACTIVE."' ";
		//echo $query;
		$sts[1]  = "selected";

		break;
	case "approved":
		$partCriteria = "WHERE  H.STATUS='"._ACTIVE."' ";
		$sts[2]  = "selected";

		break;
	case "canceled":
		$partCriteria = "WHERE  H.STATUS='"._CANCELED."' ";
		$sts[3]  = "selected";

		break;
	default:
		$partCriteria = "WHERE  H.STATUS<>'"._MONTHLY_UPDATE."' ";
		//echo $query;
		$sts[0]  = "selected";
}

//lets init the first table
echo  "<link rel=\"stylesheet\" type=\"text/css\" href=\"myMenu.css\"/>\n".

      /**
      * Global module js
      *
      */
      "<SCRIPT LANGUAGE='JavaScript' SRC='/ecs/javascript/GMisc.js'></SCRIPT> \n".

      /**
      * This module js
      *
      */
		  "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"/ecs/tocmenu_31/javascript/misc.js\"></SCRIPT> \n".
		  "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"/ecs/tocmenu_31/javascript/ajax.js\"></SCRIPT> \n".

			"<br/><br/><br/><br/><br/>\n".
			"<form action=# name='crtList' method=post>\n".
			"<table border='1'>\n".
			"<tr>\n".
			" <td>Range period1</td><td><input type='text' id='range1' name='range_period1' value='" .$_POST["range_period1"]. "' maxlength='10' align='left' style='width:100%; height:100%'></td>\n".
			" <td>Range period2</td><td><input type='text' id='range2' name='range_period2' value='" .$_POST["range_period2"]. "' maxlength='10' align='left' style='width:100%; height:100%'></td>\n".
			" <td><select name='criterialist' align='left' onchange='this.form.submit()' >".
  		"  <option value=''	$sts[0]> </option>".
  		"  <option value='pending'  $sts[1]>By Pending</option>".
  		"  <option value='approved' $sts[2]>By Approved</option>".
  		"  <option value='canceled' $sts[3]>By Canceled</option>".
  		" </select></td>".
			" <td colspan='2'><input type='submit' name='criteria' 	value='Criteria'  align='left' style='width:100%; height:100%'></td></tr>\n".
			"<tr>\n".
			"  <input      type='hidden' name='view' 	value='View'>\n".
			"  <input      type='hidden' name='radioview' 	value='".$_POST["radioview"]."'>\n".
			"</form>\n".
			"</tr>\n".
			"</table>\n".
			"<table border='1'>\n".
			"<form action=tocmenu_31/viewdboredit.php method=post>\n".
			$bodyPart.
			$optPrivs.
			"</td>\n".
			"</tr>\n".
			"</table>\n";

/**
* connect to db to retrieve data with system period as the range
*
*/
$Db = new oracleDb;
$Db->init($_SESSION["ORCL"],
           $_SESSION["OPASS"],
           $_SESSION["SID"],
           _NO_COMMENT);

if ($Db->connect()) {

  $srcDbHdr = "C_B_HDR";

  $CLFetchers->fetchLstTransaction($Db,
            	                     $partCriteria . $condt,
            	                     $SourceDb,
            	                     $nrows,
            	                     $res);

  echo  "<table border='1' class='dedeq'>\n".
        "<tr>\n".
        "<th> View/<br/>Mod         </th>\n".
        "<th> Appr/<br>Ccl/<br/>Del </th>\n".
        "<th> Date                  </th>\n".
        "<th> Status                </th>\n".
        "<th> Reference             </th>\n".
        "<th> Type                  </th>\n".
        "<th> Transaction           </th>\n".
        "<th> Supplier              </th>\n".
        "<th> JobId </th>\n".
        "</tr>\n";

  for ($i = 0; $i < $nrows; $i++) {

    switch($res["STATUS"][$i]){

      case _NOT_ACTIVE:

        $stsType = "PENDING";
        break;

      case _ACTIVE:

        $stsType = "APPROVED";
        break;

      case _CANCELED:

        $stsType = "CANCELED";
        break;

      default:
        $stsType = "ERROR!!!";
    }

    $stdPropRow = $GJs->jsOnMouseOver("GMisc.chgStyle(\"$i\",\"sBlue\");") .
                  $GJs->jsOnMouseOut ("GMisc.chgStyle(\"$i\",\"sWhite\");");

    $JID  = $res["JOB_ID"][$i];

    echo  "<tr id='$i' ".$stdPropRow.">\n".

         	  "<td> ".$GHtml->formRadio("radioview",
         	                            $JID,
         	                            _NO_PROPERTIES)."      </td>\n".

         	  "<td> ".$GHtml->formCheckBox("selbox[]",
             	                           $JID,
             	                           _NO_PROPERTIES)."  </td>\n".

            "<td> ".date("d-m-Y",
                         strtotime($res["TR_DATE"][$i]))." </td>\n".

            "<td> ".$stsType." </td>\n".

            "<td> ".$res["REFERENCE"][$i]." </td>\n".

            "<td> ".$res["IN_OUT"][$i]."    </td>\n".

            "<td> ".$res["CASH_BANK_TX_NAME"][$i]."      </td>\n".

            "<td> ".$res["SUPPLIER_CUSTOMER_NAME"][$i]." </td>\n".

            "<td> ".$res["JOB_ID"][$i]."                 </td>\n".

          "</tr>\n";
  }

  echo  "</table>\n".
  			"<br/>\n".
  			"</form>\n".
  			"</div>\n";

  $Db->dc();
}else{

  $Misc->usrDie("DB connection failed");
}

session_commit();

?>